package com.whatever;

import java.util.Random;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.*;

public class ColorBall {
	private Bitmap bitMap;
	private int X;
	private int Y;
	private int Id;
	private static int count = 1;
	private int velocityX;
	private int velocityY;
	private int width;
	private int height;
	private Random rand = new Random();
	private Context context;
	private int[] velocity = {
			1, 2, 3, 4, 5, 6, 7, 8, 9
	};
	
	public ColorBall (Context context, int coordX, int coordY) {
		BitmapFactory.Options bitMapFactory = new BitmapFactory.Options();
		bitMapFactory.inJustDecodeBounds = true;
		
		Id = count;
		count++;
		this.context = context;
		velocityX = velocity[rand.nextInt(velocity.length)];
		velocityY = velocity[rand.nextInt(velocity.length)];
		X = coordX;
		Y = coordY;
		
		WindowManager windowManager = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
		Display display = windowManager.getDefaultDisplay();
		this.width = display.getWidth();
		this.height = display.getHeight();
	}
	
	public void setVelocityX(int x) {
		velocityX = x;
	}
	
	public void setVelocityY(int y) {
		velocityY = y;
	}
	
	public void setRandomVelocity() {
		velocityX = velocity[rand.nextInt(velocity.length)];
		velocityY = velocity[rand.nextInt(velocity.length)];
	}
	
	public void setX(int x) {
		this.X = x;
	}
	
	public void setY(int y) {
		this.Y = y;
	}
	
	public int getVelocityX() {
		return velocityX;
	}
	
	public int getVelocityY() {
		return velocityY;
	}
	
	public int getX() {
		return this.X;
	}
	
	public int getY() {
		return this.Y;
	}
	
	public Bitmap getBitmap() {
		return bitMap;
	}
	
	public int getId() {
		return Id;
	}
	
	public void onMove(int x, int y, ColorBall colorball) {
		
		if(X > width) {
			X -= velocityX;
			Y -= velocityY;
			velocityX = -velocityX;
		}
		
		if(X < 0) {
			X -= velocityX;
			Y -= velocityY;
			velocityX = -velocityX;
		}
		
		if(Y > height) {
			X -= velocityX;
			Y -= velocityY;
			velocityY = -velocityY;
		}
		
		if(Y < 0) {
			X -= velocityX;
			Y -= velocityY;
			velocityY = -velocityY;
		}
		
		X += velocityX;
		Y += velocityY;
	}
}
